﻿@model TopicModel
@using Nop.Web.Models.Topics;
@{
    Layout = "~/Views/Shared/_Root.cshtml";

    if (!Model.IsPasswordProtected)
    {
        Html.AddTitleParts(!String.IsNullOrEmpty(Model.MetaTitle) ? Model.MetaTitle : Model.Title);
    }
}
@if (Model.IsPasswordProtected)
{
    <script type="text/javascript">
        $(function () {
            $('#button-password').click(function () {
                var topicId = $("#@Html.FieldIdFor(model => model.Id)").val();
                var password = $('#password').val();
                $.ajax({
                    cache: false,
                    type: 'POST',
                    url: '@Url.RouteUrl("TopicAuthenticate")',
                    data: { "id": topicId, "password": password },
                    dataType: 'json',
                    success: function (data) {
                        if (data.Authenticated) {
                            $('#ph-title .page-title h1').html(data.Title);
                            if ($('#ph-title .page-title h1').text().length == 0) {
                                $('#ph-title').hide();
                            }
                            $('#ph-topic .page-body').html(data.Body);
                            $('#ph-password').hide();
                            $('#ph-topic').show();
                        }
                        else {
                            $('#password-error').text(data.Error);
                            $('#ph-password #password').select().focus();
                        }
                    }
                });
                return false;
            });
        });

        $(document).ready(function () {
            $('#ph-topic').hide();
            $('#ph-password #password').select().focus();
        });
    </script>
    <div class="topic-password" id="ph-password">
        @using (Html.BeginRouteForm("TopicAuthenticate"))
        {
            @Html.HiddenFor(model => model.Id)
            <div class="enter-password-title">
                @T("Topic.EnterPassword")
            </div>
            <div class="enter-password-label">
                @Html.Password("password")
            </div>
            <div class="enter-password-button">
                <input type="submit" id="button-password" value="@T("Topic.Button")" />
            </div>
            <div class="password-error">
                <span id="password-error"></span>
            </div>
        }
    </div>
}
<div class="page topic-page" id="ph-topic">
    <div id="ph-title">
        <div class="page-title">
            <h1>
                @Model.Title</h1>
        </div>
    </div>
    <div class="page-body">
        @Html.Raw(Model.Body)
    </div>
</div>
